package com.wiscamp.ninechapters.problems.infrastructure.mappers.statistics;

import com.wiscamp.ninechapters.problems.infrastructure.po.statistics.MenteeGrowthPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MenteeGrowthMapper extends JpaRepository<MenteeGrowthPO, Long>, JpaSpecificationExecutor<MenteeGrowthPO> {

    @Query("select e from MenteeGrowthPO e where e.userId = :userId and e.subjectPointId = :pointId and e.growthType = :growthType and e.referenceId = :referenceId")
    MenteeGrowthPO findMenteeGrowth(long userId, long pointId, int growthType, int referenceId);

    @Query("select sum(e.growthValue) from MenteeGrowthPO e where e.userId = :userId")
    Integer findTotalGrowth(long userId);
}